package yangtuo.io.core.restful;

/**
 * <pre>
 *   http 接口 返回结果的工具类
 * </pre>
 * Created by sirius on 2018/9/19.
 *
 * @author sirius
 * @since 1.0
 */
public class ResultGenerator {

    /**
     * 无参数返回成功状态
     *
     * @return
     */
    public static Result genSuccessResult() {
        return new Result()
                .setCode(ResultCode.CODE_200.getCode())
                .setStatus(ResultCode.CODE_200.getStatus())
                .setMsg(ResultCode.CODE_200.getDescribe());
    }

    /**
     * 有参数返回成功状态
     *
     * @param data 计算结果对象
     * @return
     */
    public static Result genSuccessResult(Object data) {
        return new Result()
                .setCode(ResultCode.CODE_200.getCode())
                .setStatus(ResultCode.CODE_200.getStatus())
                .setMsg(ResultCode.CODE_200.getDescribe())
                .setData(data);
    }

    /**
     * 有参数返回失败状态
     *
     * @param message 失败原因
     * @param code    状态码
     * @return
     */
    public static Result genFailResult(String message, String code) {
        return new Result().setStatus(ResultCode.CODE_500.getStatus()).setMsg(message).setCode(code);
    }
}
